package com.lin;

import java.util.Arrays;
import java.util.Collections;

public class Solution976 {
    public static void main(String[] args) {
        int[] A = new int[]{1,2,3,4,5};
        System.out.println(largestPerimeter(A));
    }

    public static int largestPerimeter(int[] A) {
        if(A.length<3){
            return 0;
        }
        Arrays.sort(A);
        for(int i=A.length-1;i>0;i--){
            if(A[i]<A[i-1]+A[i-2]){
                return A[i-2]+A[i-1]+A[i];
            }
        }
        return 0;
    }
}
